<?php
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

declare(strict_types=1);

namespace Newbie\Generator;

use Newbie\Helper\Str;
use Psr\Container\ContainerInterface;

abstract class MineGenerator {
    /**
     * @var string
     */
    protected string $stubDir;

    protected string $dbPrefix = '';

    /**
     * @var string
     */
    protected string $namespace;

    /**
     * @var ContainerInterface
     */
    protected ContainerInterface $container;

    /**
     * Generator constructor.
     */
    public function __construct () {
        $this->setStubDir(BASE_PATH . '/newbie/generator/Stubs/');
        $this->dbPrefix  = env('DB_PREFIX', '');
        $this->container = container();
    }

    public function getStubDir (): string {
        return $this->stubDir;
    }

    public function setStubDir (string $stubDir): void {
        $this->stubDir = $stubDir;
    }

    /**
     * @return string
     */
    public function getNamespace (): string {
        return $this->namespace;
    }

    /**
     * @param mixed $namespace
     */
    public function setNamespace (string $namespace): void {
        $this->namespace = $namespace;
    }

    public function replace (): self {
        return $this;
    }

    public function getPackageName (string $subfix = "\\"): string {
        return $this->model->package_name ? Str::title($this->model->package_name) . $subfix : '';
    }
}